//
//  XRMusicMainViewController.m
//  Auditory
//
//  Created by 寒竹子 on 15/5/21.
//  Copyright (c) 2015年 寒竹子. All rights reserved.
//

#define BAR_H 30.0f

#import "XRMusicMainViewController.h"
#import "XRSegmentNavigation.h"

#import "WeekMusicViewController.h"
#import "MonthMusicViewController.h"
#import "YearMusicViewController.h"
#import "QuarterMusicViewController.h"
#import "AllMusicViewController.h"

@interface XRMusicMainViewController ()

@property (nonatomic, strong) XRSegmentNavigation * segmentNav;
@property (nonatomic, strong) NSMutableArray * viewControllers;

@end

@implementation XRMusicMainViewController

- (instancetype)init
{
    if (self = [super init]) {
        _viewControllers = [[NSMutableArray alloc] init];
    }
    
    return self;
}

- (void)setupUI
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 创建视图
    WeekMusicViewController * weekVc = [[WeekMusicViewController alloc] init];
    MonthMusicViewController * monthVc = [[MonthMusicViewController alloc] init];
    YearMusicViewController * yearVc = [[YearMusicViewController alloc] init];
    QuarterMusicViewController * quarVc = [[QuarterMusicViewController alloc] init];
    AllMusicViewController * allVc = [[AllMusicViewController alloc] init];
    
    [_viewControllers addObject:weekVc];
    [_viewControllers addObject:monthVc];
    [_viewControllers addObject:yearVc];
    [_viewControllers addObject:quarVc];
    [_viewControllers addObject:allVc];
    
    // 创建XRSegmentNavigation
    _segmentNav = [[XRSegmentNavigation alloc] initWithViewControllers:_viewControllers titles:@[@"周榜", @"月榜", @"年榜", @"季榜", @"全部"] callBlock:^(NSInteger index) {
        
    }];
    
    _segmentNav.textFont = TextFont(15.0f);
    _segmentNav.normalColor = RGB(100, 100, 100, 1.0f);
    _segmentNav.selectedColor = RGB(10, 10, 10, 1.0f);
    _segmentNav.barHeight = BAR_H+5;
    _segmentNav.backgroundColor = [UIColor whiteColor];
    _segmentNav.image = [UIImage imageNamed:@"line"];
    _segmentNav.defaultIndex = 0;
    
    [self.view addSubview:_segmentNav.view];
    
    // 传入导航
    ((WeekMusicViewController *)_viewControllers[0]).rootNav = self.rootNav;
    ((MonthMusicViewController *)_viewControllers[1]).rootNav = self.rootNav;
    ((YearMusicViewController *)_viewControllers[2]).rootNav = self.rootNav;
    ((QuarterMusicViewController *)_viewControllers[3]).rootNav = self.rootNav;
    ((AllMusicViewController *)_viewControllers[4]).rootNav = self.rootNav;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
